home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / printer / crlf.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  2.3 KB  |  90 lines

  1. ;void  crlf(num_lines);
  2. ;  unsigned short  num_lines;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.     EXTRN  _time_out:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME  CS:_TEXT
  10.     PUBLIC  _crlf
  11. _crlf    proc near
  12.     push bp            ;
  13.     mov  bp,sp        ;set stack frame
  14.     push si            ;
  15.     cmp  _memory_model,0    ;near or far?
  16.     jle  begin        ;jump if near
  17.     inc  bp            ;else add 2 to BP
  18.     inc  bp            ;
  19. begin:    mov  al,_time_out    ;get _time_out seconds
  20.     or   al,al        ;don't allow zero
  21.     jnz  L2            ;
  22.     mov  al,3        ;default to 3 seconds
  23. L2:    mov  cl,18        ;18 ticks per second
  24.     mul  cl            ;
  25.     mov  cx,[bp+4]        ;get number lines
  26.     mov  [bp+4],ax        ;save time out count
  27.     mov  ah,1        ;BIOS func to init prtr
  28.     mov  _error_code,1    ;1 = printer error
  29.     mov  dx,0        ;choose LPT1
  30.     int  17h        ;initialize the prtr port
  31.     sub  ax,ax        ;AX = 0
  32.     mov  es,ax        ;ES = 0
  33.     mov  dx,es:[408H]    ;get LPT1 base address
  34.     sub  bx,bx        ;0 = no error
  35.     jcxz L6            ;quit if zero
  36.     shl  cx,1        ;double the number
  37.     mov  bh,10        ;LF in BH
  38.     mov  ah,13        ;CR in AH
  39. L3:    xchg bh,ah        ;xchg the two values
  40.     mov  al,bh        ;get a value
  41.     out  dx,al        ;send to output data register
  42.     inc  dx            ;forward to status register
  43.     push cx            ;
  44.     call GetBiosCount    ;get timer reading
  45.     mov  si,cx        ;make copy
  46.     add  cx,[bp+4]        ;add time out
  47.     cmp  si,cx        ;if timer doesn't turn over...
  48.     jb   L4            ;go ahead
  49.     mov  cx,[bp+4]        ;time out
  50. L4:    mov  [bp+4],cx        ;time out
  51. Wait:    in   al,dx        ;get status value
  52.     test al,8        ;test for printer error
  53.     jz   L5            ;
  54.     test al,80h        ;test for Printer Ready
  55.     jnz  Ready        ;jump if ready
  56. L5:    call GetBiosCount    ;
  57.     cmp  cx,[bp+4]        ;compare to time out 
  58.     jb   Wait        ;    
  59.     pop cx            ;
  60.     jmp  short L6        ;go quit routine
  61. Ready:    pop cx            ;
  62.     inc  dx            ;output control register
  63.     mov  al,13        ;bits for strobe signal
  64.     out  dx,al        ;send the signal
  65.     dec  al            ;change to strobe OFF
  66.     out  dx,al        ;send the signal
  67.     dec  dx            ;point back to
  68.     dec  dx            ;  base address
  69.     loop L3            ;go write next char
  70.     dec  _error_code    ;0 = no error
  71. L6:    pop  si            ;
  72.     pop  bp            ;
  73.     cmp  _memory_model,0    ;quit
  74.     jle  quit        ;
  75.     db   0CBh        ;RET far
  76. quit:    ret            ;RET near
  77. GetBIOSCount PROC
  78.     push dx            ;return value in CX:DX
  79.     push ax            ;
  80.     sub  ah,ah        ;function number
  81.     int  1ah        ;get timer count
  82.     mov  cx,dx        ;low word in CX
  83.     pop  ax            ;
  84.     pop  dx
  85.     ret
  86. GetBIOSCount endp
  87. _crlf    endp
  88. _TEXT    ENDS
  89.     END
  90.